<template>
    <div id="EmergencyExercise" class="w-h-100 pos-r flex-1 apply-container page-public-s" style="box-sizing: border-box;overflow:hidden;">
        <div class="w-h-100 ver-flex pos-a" style="box-sizing: border-box; padding: 6px;">
            <div v-if="$hasPer('EmergencyExercise:add') || $hasPer('EmergencyExercise:excel')" style="box-sizing: border-box;">
                <el-card shadow="never" :body-style="{ paddingBottom: '0' }">
                    <el-form class="box-f" ref="queryForm" :inline="true">
                        <el-form-item >
                            <el-button @click="nodeClick('','add')" icon="ele-Plus" type="primary"> 新增 </el-button>
                            <el-button @click="handleExport" icon="ele-Download"> 导出数据 </el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </div>

            <div style="box-sizing: border-box;" class="flex-1 pos-r">
                <div class="pos-a w-h-100" style="box-sizing: border-box;">
                    <el-card class="box-card w-h-100" shadow="never" style="margin-top: 16px;">
                        <div style="" class="w-h-100 ver-flex">
                            <div class="flex-1 pos-r">
                                <div class="pos-a w-h-100">
                                    <el-table ref="excelRef" :data="list" class="w-h-100" style="width: 100%" border v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.5)">
                                        <!-- <el-table-column type="index" label="序号" width="55" :show-overflow-tooltip="true" align="center" :index="indexMethod" /> -->

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="应急演练计划"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="s_Plan" typeVal="select" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_DRPlanName">{{ scope.row.v_DRPlanName }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="应急演练记录名称"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="i_Name" typeVal="input" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_Name">{{ scope.row.v_Name }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="主管部门"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="s_Org" typeVal="cascader" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_OrgName">{{ scope.row.v_OrgName }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="负责人"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="i_Principal" typeVal="input" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_Principal">{{ scope.row.v_Principal }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column width="230" :show-overflow-tooltip="true" label="演练开始时间"  align="center" prop="d_StartTime" sortable>
                                            <el-table-column :show-overflow-tooltip="true" width="230" align="center">
                                                <template #header>
                                                    <SearchModel typeId="i_StarTime" typeVal="datetime" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.d_StartTime">{{ scope.row.d_StartTime }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column width="230" :show-overflow-tooltip="true" label="演练结束时间"  align="center" prop="d_EndTime" sortable>
                                            <el-table-column :show-overflow-tooltip="true" width="230" align="center">
                                                <template #header>
                                                    <SearchModel typeId="i_EndTime" typeVal="datetime" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.d_EndTime">{{ scope.row.d_EndTime }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="应急演练方式"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="s_Mode" typeVal="select" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_Mode">{{ scope.row.v_Mode }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="200" :show-overflow-tooltip="true" label="应急演练类型"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <SearchModel typeId="s_Type" typeVal="select" @searchHandel="searchHandel" :basicsInfo="basicsInfo" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_Type">{{ scope.row.v_Type }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="180" :show-overflow-tooltip="true" prop="createdTime" label="创建时间"  align="center" sortable>
                                            <template #default="scope">
                                                <span v-if="scope.row.createdTime">{{ scope.row.createdTime }}</span>
                                                <span v-else>-</span>
                                            </template>
                                        </el-table-column>

                                        <el-table-column min-width="180" :show-overflow-tooltip="true" prop="updatedTime" label="更新时间"  align="center" sortable>
                                            <template #default="scope">
                                                <span v-if="scope.row.updatedTime">{{ scope.row.updatedTime }}</span>
                                                <span v-else>-</span>
                                            </template>
                                        </el-table-column>

                                        <el-table-column min-width="260" label="操作" align="center" fixed="right">
                                            <el-table-column :show-overflow-tooltip="true" min-width="260" align="center">
                                                <template #header>
                                                    <el-button class="icon-e" @click='searchClick' icon="ele-Search" size="small" type="primary" text> 查询 </el-button>
                                                    <el-button class="icon-e clear-bg" style="background-color: transparent !important;" size="small" @click="resetClick" icon="ele-Refresh" text> 重置 </el-button>
                                                </template>
                                                <template #default="scope">
                                                    <div class="operate-s">
                                                        <el-button @click="detailHandle(scope.row.id)" class="icon-e" icon="ele-View" size="small" text type="success">详情</el-button>
                                                        <el-button v-if="$hasPer('EmergencyExercise:edit')" @click="nodeClick(scope.row,'edit')" class="icon-e" icon="ele-Edit" size="small" text type="primary">编辑</el-button>
                                                        <el-button v-if="$hasPer('EmergencyExercise:del')" @click="deleteHandle(scope.row.id, getData)" class="icon-e" icon="ele-Delete" size="small" text type="danger">删除</el-button>
                                                        <el-dropdown v-if="$hasPer('EmergencyExercise:drill') && $hasPer('EmergencyExercise:record') && $hasPer('EmergencyExercise:assess')" trigger="click">
                                                            <el-button style="margin-left: 10px;" class="el-dropdown-link" size="small" text type="warning">文档上传<el-icon class="el-icon--right"><arrow-down /></el-icon></el-button>
                                                            <template #dropdown>
                                                                <el-dropdown-menu class="el-dropdown-menu-s">
                                                                    <el-dropdown-item v-if="$hasPer('EmergencyExercise:drill')" @click="documentClick(scope.row, 1)" icon="Upload">演练方案文档</el-dropdown-item>
                                                                    <el-dropdown-item v-if="$hasPer('EmergencyExercise:record')" @click="documentClick(scope.row, 2)" icon="CollectionTag">现场记录资料</el-dropdown-item>
                                                                    <el-dropdown-item v-if="$hasPer('EmergencyExercise:assess')" @click="documentClick(scope.row, 3)" icon="EditPen">演练效果评估</el-dropdown-item>
                                                                </el-dropdown-menu>
                                                            </template>
                                                        </el-dropdown>
                                                    </div>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                    </el-table>
                                </div>
                            </div>
                            <div style="height: 30px;margin-top: 20px;" class="hr-flex-start">
								<el-pagination
									v-model:currentPage="pageNo"
									v-model:page-size="pageSize"
									:total="totalRows"
									:page-sizes="[10, 20, 50, 100]"
									small
									background
									@size-change="handleSizeChange"
									@current-change="handleCurrentChange"
									layout="total, sizes, prev, pager, next, jumper"
									class="w-h-100"
								/>
							</div>
                        </div>
                    </el-card>
                </div>
            </div>
        </div>
        <!-- 新增/编辑 -->
        <AddEditEmergencyExercise
            :repairInfo="repairInfo"
            :isUseDialog="isUseDialog"
            @updateData="getData"
            @cancelUseClick="cancelUseClick"
            @controlUseClick="controlUseClick"
        />
        <!-- 演练方案文档上传 -->
        <uploadFile
            :isAccept="isAccept"
            :fileInfo="fileInfo"
            :isUseDialog="fileDialog"
            @cancelFileClick="cancelFileClick"
            @controlFileClick="controlFileClick"
            @updateData="getData"
        ></uploadFile>
        <!-- 详情 -->
        <DetailModel
            :detailInfo="detailInfo"
            :MdetailDialog="MdetailDialog"
            labelWidth="140px"
            @cancelDetailClick="cancelDetailClick"
        />
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, Ref, onMounted , reactive , toRaw } from 'vue';
import getTableData from '/@/utils/getTableData';
import { 
    SMSDRRecordPage , 
    SMSDRRecordDelete , 
    sysDictDataList , 
    SMSDRPlanList ,
    SMSDRRecordDetail,
} from '/@/api/centerControl/sms';
import AddEditEmergencyExercise from '../component/sms/add-edit-EmergencyExercise.vue';
import { ElMessageBox , ElMessage } from 'element-plus';
import uploadFile from '../component/uploadFile.vue';
import { sysOrgTree , sysFileInfoPage } from '/@/api/centerControl/pubilc';
import SearchModel from '../component/search-model.vue';
import DetailModel from '../component/detail-model.vue';
import { exportToExcel } from '/@/utils/exportToExcel';

export default defineComponent( {
    name: 'EmergencyExercise',
    components: {
        AddEditEmergencyExercise,
        uploadFile,
        SearchModel,
        DetailModel,
    },
    setup(props){
        const isUseDialog = ref() // 新增/编辑弹出框隐藏/显示
        const repairInfo = ref() // 传递子组件数据
        const fileInfo = ref();
        const fileDialog = ref(false);
        const isAccept = ref();

        /*** nodeClick 新增/编辑点击事件 */
        const nodeClick = (val:string | object , am:string) => {
            val !== '' ? repairInfo.value = JSON.stringify(toRaw(val)) : repairInfo.value = ''
            isUseDialog.value = true
        };

        /*** deleteHandle 删除数据事件 */
        const deleteHandle = async (val: String | Number, updateFun: Function) => {
            ElMessageBox.confirm('请确定删除此条数据？','提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }
            )
            .then(async() => {
                let param = {id : val};
                try {
                    let res:any = await SMSDRRecordDelete(param);
                    if(res.success){
                        updateFun()
                    }
                } catch (err) { return }
            })
            .catch(() => {
                ElMessage({
                    type: 'info',
                    message: '已取消',
                })
            })
        };

        /*** cancelUseClick 取消事件 */
        const cancelUseClick = () => {
            isUseDialog.value = false
        };

        /*** controlUseClick 提交事件 */
        const controlUseClick = () => {
            isUseDialog.value = false
        };
        
        /*** documentClick 文档上传事件 */
        const documentClick = (val:any, num: number) => {
            console.log(num,'num')
            switch(num){
                case 1:
                    val.sourceType = 10;
                    val.sourceId = val.l_SchemeFileId;
                    val.titleCon = '方案文档';
                    isAccept.value = '';
                    fileInfo.value = JSON.stringify(val);
                    fileDialog.value = true;
                    break;
                case 2:
                    val.sourceType = 10;
                    val.sourceId = val.l_OnSpotRecordFileId;
                    val.titleCon = '现场记录资料文档';
                    isAccept.value = '';
                    fileInfo.value = JSON.stringify(val);
                    fileDialog.value = true;
                    break;
                case 3:
                    val.sourceType = 10;
                    val.sourceId = val.l_EffectAppraisalFileId;
                    val.titleCon = '效果评估文档';
                    isAccept.value = '';
                    fileInfo.value = JSON.stringify(val);
                    fileDialog.value = true;
                    break;
            }
        }
        
        /*** cancelFileClick 文件上传取消事件 */
        const cancelFileClick = () => {
            fileDialog.value = false;
        };

        /*** controlFileClick 文件上传提交事件 */
        const controlFileClick = () => {
            fileDialog.value = false;
        }

        /*** ================================= 详情类数据操作 =================================  */
        const MdetailDialog = ref(false);
        const detailInfo = ref();

        // 获取文件
        const getFileFun = async (sourceId: number) => {
            let param: any = {};
            param.PageNo = 1;
            param.PageSize = 99999;
            param.sourceId = sourceId;
            let res: any = await sysFileInfoPage(param);
            if(res.success) return res.data.rows;
        }

        /*** 获取详情接口数据 */
        const getDetailFun = async (id: number) => {
            let res: any = await SMSDRRecordDetail({id: id}); // 详情
            if(res.success){
                console.log(res.data,'res.data')
                let setArr: any = [];
                let tableArrOne: any = [];
                let tableArrTwo: any = [];
                let tableArrThree: any = [];
                let detailObj: any = {};
                let sourceIdArr: any = [];
                
                if(res.data.l_SchemeFileId){
                    await getFileFun(res.data.l_SchemeFileId).then((fileVal: any) => {
                        if(fileVal.length !== 0){
                            fileVal.map((val: any) => {
                                let itemObj: any = {};
                                itemObj['id'] = val.id;
                                itemObj['fileObjectName'] = val.fileObjectName;
                                itemObj['附件名称'] = val.fileOriginName;
                                itemObj['文件格式'] = val.fileSuffix;
                                itemObj['文件大小'] = val.fileSizeKb;
                                itemObj['文件路径'] = val.filePath;
                                tableArrOne.push(itemObj);
                            });
                        }
                    })
                }

                if(res.data.l_OnSpotRecordFileId){
                    await getFileFun(res.data.l_OnSpotRecordFileId).then((fileVal: any) => {
                        if(fileVal.length !== 0){
                            fileVal.map((val: any) => {
                                let itemObj: any = {};
                                itemObj['id'] = val.id;
                                itemObj['fileObjectName'] = val.fileObjectName;
                                itemObj['附件名称'] = val.fileOriginName;
                                itemObj['文件格式'] = val.fileSuffix;
                                itemObj['文件大小'] = val.fileSizeKb;
                                itemObj['文件路径'] = val.filePath;
                                tableArrTwo.push(itemObj);
                            });
                        }
                    })
                }

                if(res.data.l_EffectAppraisalFileId){
                    await getFileFun(res.data.l_EffectAppraisalFileId).then((fileVal: any) => {
                        if(fileVal.length !== 0){
                            fileVal.map((val: any) => {
                                let itemObj: any = {};
                                itemObj['id'] = val.id;
                                itemObj['fileObjectName'] = val.fileObjectName;
                                itemObj['附件名称'] = val.fileOriginName;
                                itemObj['文件格式'] = val.fileSuffix;
                                itemObj['文件大小'] = val.fileSizeKb;
                                itemObj['文件路径'] = val.filePath;
                                tableArrThree.push(itemObj);
                            });
                        }
                    })
                }
                detailObj['应急演练计划'] = res.data.v_DRPlanName;
                detailObj['应急演练名称'] = res.data.v_Name;
                detailObj['主管部门'] = res.data.v_OrgName;
                detailObj['负责人'] = res.data.v_Principal;
                detailObj['演练开始时间'] = res.data.d_StartTime;
                detailObj['演练结束时间'] = res.data.d_EndTime;
                detailObj['应急演练方式'] = res.data.v_Mode;
                detailObj['应急演练类型'] = res.data.v_Type;
                setArr = [{
                    formTitle: '基础信息',
                    type: 'form',
                    info: detailObj,
                },{
                    tableTitle: '方案文档附件数据',
                    type: 'table',
                    listData: tableArrOne,
                    minWidth: 160,
                    isShowBtn: true,
                },{
                    tableTitle: '现场记录资料文档附件数据',
                    type: 'table',
                    listData: tableArrTwo,
                    minWidth: 160,
                    isShowBtn: true,
                },{
                    tableTitle: '效果评估文档附件数据',
                    type: 'table',
                    listData: tableArrThree,
                    minWidth: 160,
                    isShowBtn: true,
                }];
                detailInfo.value = setArr;
                MdetailDialog.value = true;
            }
        }
        /*** 详情 */
        const detailHandle = (id: number) => {
            getDetailFun(id);
        }
        /*** 详情关闭事件 */
        const cancelDetailClick = () => {
            MdetailDialog.value = false;
        }
        /*** ================================= 详情类数据操作 =================================  */
        
        /*** ================================= 查询类数据操作 =================================  */
        let searchObj:any = reactive({
            isContainNullEndDate: true,
        });
        const basicsInfo: any = ref([]);
        const searInfo: any = ref();

        /*** 获取需要查询的数据 */
        const searchHandel = (val: any) => {
            searInfo.value = val;
        }

        /*** 合法性判断 */
        const legalFun = async (valOne: any, valTwo: any, hintTitle: string, hintInfo: string) => {
            let isLegal = true;
            if(valTwo && !valOne){
                ElMessage({
                    type: 'error',
                    message: hintTitle,
                });
                isLegal = false;
            }
            if(valOne && valTwo){
                const dateMin = new Date(valOne).getTime();
                const dateMax = new Date(valTwo).getTime();
                console.log(dateMin,dateMax,'dateMax')
                if(dateMin >= dateMax){
                    ElMessage({
                        type: 'error',
                        message: hintInfo,
                    });
                    isLegal = false;
                }
            }
            return isLegal;
        }

        /*** 查询按钮 */
        const searchClick = async () => {
            let isLegal = true;
            if(searInfo.value.d_PlanEndTimeMax){
                isLegal = await legalFun(
                    searInfo.value.d_StartTimeMin, 
                    searInfo.value.d_EndTimeMax, 
                    '请选择演练开始时间',
                    '演练开始时间不能大于或等于演练结束时间'
                ); 
            }
            if(!isLegal) return;
            let newObj = Object.keys(searInfo.value);
            if(newObj.length !== 0){
                newObj.map((i:any) => {
                    searchObj[i] = searInfo.value[i];
                });
            }
        };

        /*** 重置按钮 */
        const resetClick = () => {
            searInfo.value = {};
            let newObj = Object.keys(searchObj);
            if(newObj.length !== 0){
                newObj.map((i:any) => {
                    searchObj[i] = ''
                });
            }
            searchObj.isContainNullEndDate = true;
            initInfoFun();
        };

        let orgArr: any = [];
        let modeArr: any = [];
        let typeArr: any = [];
        let planArr: any = [];
        // 获取数据
        const getFun = async () => {
            let ras: any = await sysOrgTree({}); // 获取组织架构树
            let rbs: any = await sysDictDataList({TypeCode: 'ExerciseWay'}); // 演练方式
            let rcs: any = await sysDictDataList({TypeCode: 'ExerciseType'}); // 演练类型
            let res: any = await SMSDRPlanList({});
            if(ras.success && ras.data.length !== 0){
                orgArr = ras.data;
            }
            if(rbs.success && rbs.data.length !== 0) {
                rbs.data.map((item: any) => {
                    item.label = item.value;
                    item.value = item.value;
                });
                modeArr = rbs.data;
            }
            if(rcs.success && rcs.data.length !== 0) {
                rcs.data.map((item: any) => {
                    item.label = item.value;
                    item.value = item.value;
                });
                typeArr = rcs.data;
            }
            if(res.success && res.data.length !== 0) {
                res.data.map((item: any) => {
                    item.label = item.v_Name;
                    item.value = item.id;
                });
                planArr = res.data;
            }
        }
        
        /*** 初始化数据 */
        const initInfoFun = () => {
            basicsInfo.value = [{
                    typeId: 'i_Name', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'v_Name', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '应急演练名称', // placeholder数据
                    defaultProp: '', // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: 'burl', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: 'nameEvent', // 事件名称 --- 选填
                },{
                    typeId: 's_Plan', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'l_DRPlanId', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '应急演练计划', // placeholder数据
                    defaultProp: planArr, // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: 'change', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: 'planChange', // 事件名称 --- 选填
                },{
                    typeId: 'i_StarTime', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'd_StartTimeMin', // 查询字段 --- 必填
                    // searchValMax: 'd_StartTimeMax', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '演练开始时间', // placeholder数据
                    defaultProp: '', // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: 'change', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: 'dateChange', // 事件名称 --- 选填
                },{
                    typeId: 'i_EndTime', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    // searchValMin: 'd_EndTimeMin', // 查询字段 --- 必填
                    searchVal: 'd_EndTimeMax', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '演练结束时间', // placeholder数据
                    defaultProp: '', // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: 'change', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: 'dateChange', // 事件名称 --- 选填
                },{
                    typeId: 's_Org', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'l_OrgId', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '主管部门', // placeholder数据
                    defaultProp: orgArr, // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: 'change', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: 'orgChange', // 事件名称 --- 选填
                    propsVal: { checkStrictly: true , label: 'title', value: 'id', children: 'children' }, // 级联选择器 --- 选填
                },{
                    typeId: 'i_Principal', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'v_Principal', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '负责人', // placeholder数据
                    defaultProp: '', // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: 'burl', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: 'principalEvent', // 事件名称 --- 选填
                },{
                    typeId: 's_Mode', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'v_Mode', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '应急演练方式', // placeholder数据
                    defaultProp: modeArr, // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: 'change', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: 'modeChange', // 事件名称 --- 选填
                },{
                    typeId: 's_Type', // 类型(不能为空，且唯一，与组件中typeId值对应) --- 必填
                    typeNam: '', // 输入类型(number,text等) --- 选填
                    searchVal: 'v_Type', // 查询字段 --- 必填
                    defaultVal: '', // 字段默认值 --- 选填
                    placeholder: '应急演练类型', // placeholder数据
                    defaultProp: typeArr, // 下拉框中使用，除下拉框外其它情况为空 --- 选填
                    eventType: 'change', // 事件类型（如burl/change等） --- 选填
                    defaultEvent: 'typeChange', // 事件名称 --- 选填
                }
            ]
        }
        
        onMounted(async () => {
            await getFun();
            initInfoFun(); 
        });
        /*** ================================= 查询类数据操作 =================================  */

        /*** ================================= 导出数据函数操作 ================================= */
        const excelRef: any = ref(null);
        const handleExport = () => {
            if(excelRef){
                if(excelRef.value.data.length !== 0){
                    let tableExcel: any = [];
                    let tableArr = excelRef.value.data;
                    tableArr.map((item: any) => {
                        let tableObj: any = {};
                        tableObj['应急演练计划'] = item.v_DRPlanName ? item.v_DRPlanName : '-';
                        tableObj['应急演练名称'] = item.v_Name ? item.v_Name : '-';
                        tableObj['主管部门'] = item.v_OrgName ? item.v_OrgName : '-';
                        tableObj['负责人'] = item.v_Principal ? item.v_Principal : '-';
                        tableObj['演练开始时间'] = item.d_StartTime ? item.d_StartTime : '-';
                        tableObj['演练结束时间'] = item.d_EndTime ? item.d_EndTime : '-';
                        tableObj['应急演练方式'] = item.v_Mode ? item.v_Mode : '-';
                        tableObj['应急演练类型'] = item.v_Type ? item.v_Type : '-';                        
                        tableExcel.push(tableObj);
                    });
                    exportToExcel(tableExcel,'应急演练记录.xlsx');
                }else{
                    ElMessage({
                        type: 'error',
                        message: '暂无数据导出',
                    })
                }
            }
        }
        /*** ================================= 导出数据函数操作 ================================= */

        return {
            ...getTableData(SMSDRRecordPage,{},searchObj),
            isUseDialog,
            cancelUseClick,
            controlUseClick,
            nodeClick,
            repairInfo,
            deleteHandle,

            searchOptions: [{
                value: '1',
                label: '培训计划'
            },{
                value: '2',
                label: '考题类型'
            }], // 搜索方式
            responsiblePle: [
                {label: '单选' , value: 0},
                {label: '多选' , value: 1},
                {label: '判断' , value: 2},
            ],
            documentClick,
            fileInfo,
            fileDialog,
            cancelFileClick,
            controlFileClick,
            isAccept,

            // 导出Excel
            excelRef,
            handleExport,
            
            // 详情
            MdetailDialog,
            detailHandle,
            detailInfo,
            cancelDetailClick,

            // 查询事件
            basicsInfo,
            searchHandel,
            searchClick,
            resetClick,
        }
    },
} )
</script>
<style lang="scss"> @import '../style/public.scss'; </style>
<style scoped lang="scss">
    #EmergencyExercise {
        .box-f{
            :deep(.el-form-item__label){
                padding: 0;
            }
        }
        :deep(.el-card__body) {
            height: 100%;
        }
        :deep(.el-card){
            border: none !important;
        }
        .upload-demo{
            margin-left: 12px;
            margin-top: 2px;
        }
        ul {

            list-style: none;

            li {
                cursor: pointer;

                &:hover {
                    color: red;
                }
            }
        }
        .icon-e{
            :deep(.el-icon){
                margin-right: 0px!important;
            }
        }
    }
.clear-bg{
    background-color: transparent !important;
}
</style>